import { service } from '@/api/utils/request';
import type { AxiosResponse } from 'axios';

type API_ENUM = {
  name: string;
  path: string;
  showMessage: boolean;
  meth?: string
};

export const hocksApi = <T>(api: API_ENUM, params: any, handleResponse: (response: AxiosResponse<any>) => T) => {
  const post = (): Promise<T> => {

    return service(api).post(api.path, params)
      .then((response: AxiosResponse<any>) => handleResponse(response));
  }

  const get = (): Promise<T> => {
    return service(api).get(api.path, params)
      .then((response: AxiosResponse<any>) => handleResponse(response));
  }

  return { post, get };
}